﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Fulcrum.ViewModelGenerator.UnitTests
{
    partial class TestSample4
    {
        InnerObject inner;

        public TestSample4()
        {
            this.inner = new InnerObject();
            RegisterPassThroughPropertySourceObjects();
        }

        public void SetInt(int value)
        {
            this.inner.WrappedInt = value;
        }

        partial void OnWrappedIntChangedImplementation()
        {
            this.WrappedIntChangedCallCount++;
        }

        partial void OnWrappedStringChangedImplementation()
        {
            this.WrappedStringChangedCallCount++;
        }

        public int WrappedIntChangedCallCount
        {
            get;
            private set;
        }

        public int WrappedStringChangedCallCount
        {
            get;
            private set;
        }

        class InnerObject : INotifyPropertyChanged
        {
            int wrappedInt = 6;
            string aString = "my string";

            public InnerObject()
            {
                // nothing
            }

            public int WrappedInt
            {
                get
                {
                    return this.wrappedInt;
                }
                set
                {
                    this.wrappedInt = value;
                    OnPropertyChanged("WrappedInt");
                }
            }

            public string AString
            {
                get
                {
                    return this.aString;
                }
                set
                {
                    this.aString = value;
                    OnPropertyChanged("AString");
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;

            private void OnPropertyChanged(string propertyName)
            {
                var eh = this.PropertyChanged;

                if (eh != null)
                {
                    eh(this, new PropertyChangedEventArgs(propertyName));
                }
            }
        }
    }
}
